//============================================================================
// Name        : t_object.cpp
// Author      : inkooboo
// Version     :
// Copyright   :
// Description : main in C++
//============================================================================

#include <OgreRoot.h>


#include "core/object.hpp"

#include <boost/timer.hpp>
#include <boost/foreach.hpp>

#include <iostream>
#include <vector>

using namespace std;

static const int number = 1000000;

int main(void) {

  Ogre::Root *root = new Ogre::Root("","");
  Ogre::SceneManager *scene = root->createSceneManager("DefaultSceneManager");

  vector<boost::shared_ptr<object_t> > objs;

  cout << "Creating of " << number << " objects iterating vector via index ... ";
  boost::timer timer;
  objs.resize(number);
  for (int i=0; i<number; ++i) {
    objs[i] = object_t::create(scene, "bear.od");
  }
  cout << timer.elapsed() << " sec" << endl;
  objs.resize(0);

  cout << "Creating of " << number << " objects iterating vector via iterator ... ";
  timer.restart();
  objs.resize(number);
  int i = 0;
  for (vector<boost::shared_ptr<object_t> >::iterator it=objs.begin(); it!=objs.end(); ++it) {
    *it = object_t::create(scene, "bear.od");
  }
  cout << timer.elapsed() << " sec" << endl;
  objs.resize(0);

  cout << "Creating of " << number << " objects iterating vector via BOOST_FOREACH ... ";
  timer.restart();
  objs.resize(number);
  i = 0;
  BOOST_FOREACH( boost::shared_ptr<object_t>& it, objs ) {
    it = object_t::create(scene, "bear.od");
  }
  cout << timer.elapsed() << " sec" << endl;
  objs.resize(0);

  return EXIT_SUCCESS;
}
